package com.lonely.web.controller.system;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.lonely.common.core.domain.Cascader;
import com.lonely.common.core.domain.Select;
import com.lonely.common.core.domain.api.R;
import com.lonely.system.domain.entity.SysProductionLine;
import com.lonely.system.domain.dto.productionline.SysProductionLineStatQueryDto;
import com.lonely.system.domain.dto.productionline.SysProductionLineSubmitDto;
import com.lonely.system.domain.vo.system.productionline.SysProductionLineStatsVo;
import com.lonely.system.service.ISysProductionLineService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * @author: 黄志标
 * @date: 2025/5/27 11:36
 * @description: 产线管理处理类
 */
@RestController
@RequestMapping("/systemManage/productionLine")
@Api(tags = "系统管理/产线管理")
public class SysProductionLineController {

    @Autowired
    private ISysProductionLineService sysProductionLineService;


    /**
     * 创建产线
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/create")
    @SaCheckPermission("system:productionLine:create")
    @ApiOperation(value = "创建产线")
    public R<Boolean> create(@RequestBody @Validated SysProductionLineSubmitDto submitDto) {
        this.sysProductionLineService.create(submitDto);
        return R.status(true);
    }

    /**
     * 编辑产线
     *
     * @param submitDto
     * @return
     */
    @PostMapping("/edit")
    @SaCheckPermission("system:productionLine:edit")
    @ApiOperation(value = "编辑产线")
    public R<Boolean> edit(@RequestBody @Validated SysProductionLineSubmitDto submitDto) {
        this.sysProductionLineService.edit(submitDto);
        return R.status(true);
    }


    /**
     * 产线统计
     *
     * @return
     */
    @PostMapping("/stat")
    @ApiOperation(value = "获取产线统计信息")
    public R<SysProductionLineStatsVo> stat(@RequestBody @Validated SysProductionLineStatQueryDto queryDto) {
        return R.data(this.sysProductionLineService.stat(queryDto));
    }

    /**
     * 产线下拉框列表
     *
     * @return
     */
    @GetMapping("/getSelect/{factoryId}")
    @ApiOperation(value = "产线下拉框列表")
    public R<List<Select>> getSelect(@PathVariable("factoryId") Long factoryId) {
        return R.data(this.sysProductionLineService.getSelect(factoryId));
    }

    /**
     * 产线对应的生产工种下拉框列表
     *
     * @return
     */
    @GetMapping("/getWorkTypeSelect/{productionLineId}")
    @ApiOperation(value = "产线对应的生产工种下拉框列表")
    public R<List<Select>> getWorkTypeSelect(@PathVariable("productionLineId") Long productionLineId) {
        return R.data(this.sysProductionLineService.getWorkTypeSelect(productionLineId));
    }


    /**
     * 获取产线信息
     *
     * @param plId
     * @return
     */
    @GetMapping("/detail/{plId}")
    @ApiOperation(value = "获取产线信息")
    public R<SysProductionLine> detail(@PathVariable("plId") Long plId) {
        return R.data(this.sysProductionLineService.getById(plId));
    }

    /**
     * 暂停分单
     *
     * @param plId
     * @return
     */
    @GetMapping("/suspendSplitOrders/{plId}")
    @SaCheckPermission("system:productionLine:suspendSplitOrders")
    @ApiOperation(value = "暂停分单")
    public R<Boolean> suspendSplitOrders(@PathVariable("plId") Long plId) {
        this.sysProductionLineService.suspendSplitOrders(plId);
        return R.status(true);
    }

    /**
     * 停用产线/分组
     *
     * @param plId
     * @return
     */
    @GetMapping("/stopUsing/{plId}")
    @ApiOperation(value = "停用产线/分组")
    @SaCheckPermission("system:productionLine:stopUsing")
    public R<Boolean> stopUsing(@PathVariable("plId") Long plId) {
        this.sysProductionLineService.stopUsing(plId);
        return R.status(true);
    }

    /**
     * 获取产线级联选择器数据
     *
     * @return
     */
    @GetMapping("/getProductionLineCascader")
    @ApiOperation("获取产线级联选择器数据")
    public R<List<Cascader>> getProductionLineCascader() {
        return R.data(this.sysProductionLineService.getProductionLineCascader());
    }
}
